package com.bcts.rrh.drawingboard.shapeview;

import android.graphics.Canvas;
import com.bcts.rrh.drawingboard.Constants;
import java.util.List;
import java.util.Vector;

public class PathList {//路径集合
    public List<Pathview> paths=null;
    //private ListIterator<Pathview> it=paths.listIterator();//创建迭代器，从后往前取
    private float x = 0, y = 0;

    public PathList(){
        paths=new Vector<Pathview>();
    }
    public void draw(Canvas canvas){
        canvas.save();
        canvas.translate(getX(), getY());
        for (Pathview p : paths) {
            p.drawview(canvas);
        }
        canvas.restore();
    }
    public void addPathView(Pathview pathview) {
        paths.add(pathview);
    }

    public void removePathView(float x,float y) {//橡皮擦的区域删除
        for (Pathview p : paths){
            p.Contains(x,y);//判断触点是否在图形上
            if(p.moveable==true){
                paths.remove(p);
                break;
            }
        }
        /*for (Pathview p : paths){
            if(p.moveable==true){
                paths.remove(p);
            }
        }*/
    }

    public void clear(){
        paths.clear();
    }
    public void moveable(float x,float y){//遍历pathList查找点击点在哪个Path上
        for (Pathview p : paths){
            p.Contains(x,y);
                p.movestrat(x,y);
        }
    }

    public void rotateable(float x,float y){//遍历pathList查找点击点在哪个Path上
        for (Pathview p : paths){
            p.Contains(x,y);
            p.rotateViewPressed(x,y);
        }
    }

    /**
     * 根据触动判断返回的Pathview对象
     * @param x
     * @param y
     * @return
     */
    public Pathview returnView(float x,float y){
        for (Pathview p: paths){
            p.Contains(x,y);
            if(p.moveable==true){
                return p;
            }
        }
        return null;
    }

    public void setFill(float x,float y){
        for (Pathview p: paths){
            p.Contains(x,y);
            if(p.moveable==true){
                p.setFill(Constants.penColor);
                break;//跳出循环，则每次只能填充一个图形
            }
        }
    }

    public float getX() {
        return x;
    }
    public float getY() {
        return y;
    }
}
